/*
* @Author: Administrator
* @Date:   2018-01-08 15:59:48
* @Last Modified by:   Administrator
* @Last Modified time: 2018-01-15 13:27:29
*/
'use strict' ;
require('./index.css');
var _mm		=require('util/mm.js');

//通用页面头部
var header={
 	init:function () {
 		this.onload();
 		this.bindEvent();

 		return this ;
 	},
 	//keyword存在回填输入框
 	onload :function(){
 		var keyword = _mm.getUrlParam('keyword');
 		if (keyword) {
 			$('#search-input').val(keyword);
 		}
 	},
 	//按钮的提交
 	bindEvent:function(){
 		var _this=this;
 		//点击搜索按钮之后做搜索提交
 		$('#search-btn').click(function(){
 			_this.searchSubmit();
 		});
 		//输入回车后也做搜索提交
 		$('#search-input').keyup(function(e){
 			//13是回车键的keyCode
 			if (e.keyCode===13) {
 				_this.searchSubmit();
 			}
 		});
 	
 	},
 	//搜索的提交
 	searchSubmit :function (){
 		var keyword=$.trim($('#search-input').val());
 		//如果提交的时候有keyword。正常跳转到list页面 
 		if (keyword) {
 			window.location.href='./list.html?keyword='+keyword;
 		}else{
 			//如果keyword为空，直接调回首页
 			_mm.goHome();
 		}

 	}
 };
header.init();